Recently we faced an issue accessing the Tier 2 Database through X++ code. We can use the X++ method below to get the Connection String for connecting the Tier 2 Environment Database.
You can use the following X++ code to obtain the connection string and pass it to your C# class:
SQL System:managedConnectionString();
This method returns the connection string value, which can either be stored in a variable or directly passed to your C# class.
The SQL System class is used for working with SQL Server databases. It provides methods for executing SQL queries, managing transactions, and handling database connections. The SQL System:managedConnectionString(); method retrieves the connection string for the current user's session. This is useful when you want the system's connection string for connecting to SQL Server for the current user.